import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy'
import { PROXY_RULE } from './src/publicConfig'
// https://vitejs.dev/config/
export default defineConfig({
  define: {
    'process.env': process.env
  },
  // base: './',
  plugins: [
    vue(),
    legacy({
      targets: ['defaults', 'not IE 11']
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import "@/styles/public.scss";`,
        javascriptEnabled: true
      }
    }
  },
  server: {
    // host: '52.53.239.2',
    // open: true,
    port: '8081',
    proxy: PROXY_RULE
  },
  build: {
    rollupOptions: {
      output: {
        // 入口文件和代码分割后的文件名仍保留哈希值
        entryFileNames: 'assets/js/[name]-[hash].js',
        chunkFileNames: 'assets/js/[name]-[hash].js',
        // assets文件夹下的资源文件名去除哈希值
        assetFileNames: 'assets/[name].[ext]',
      },
    },
  },
})
